#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,V,spout,sppout,p[1000005],tsqk=0,mmin;
int pd[1000005];
struct Ndddd
{
    int d,v,a;
} lst[1000005];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>L>>V;
        mmin=1;
        spout=0;
        for(int i=1; i<=n; i++)
        {
            cin>>lst[i].d>>lst[i].v>>lst[i].a;
            tsqk+=lst[i].a;
        }
        for(int i=1; i<=m; i++)
        {
            cin>>p[i];
            pd[i]=0;
        }
        for(int i=1; i<=n; i++)
        {
            if(lst[i].a==0&&lst[i].v>V)
            {
                spout++;
            }
            else
            {
                double addre=(9-lst[i].v*lst[i].v)/(2.0*lst[i].a)+lst[i].d;
                if(lst[i].a>0)
                {
                    if(addre<=p[m])
                    {
                        spout++;
                    }
                    for(int j=1; j<=m; j++)
                    {
                        if(addre>=p[j])
                        {
                            pd[j]++;
                        }
                    }
                }

                else if(lst[i].a<0)
                {
                    bool xxx=1;
                    for(int j=1; j<=m; j++)
                    {
                        if(lst[i].d<=p[j]&&p[j]<=addre)
                        {
//                             cout<<"chao"<<i<<endl;
                            if(xxx)
                            {
                                spout++;
                                xxx=0;
                            }
                            pd[j]++;
                        }
                    }
                }
            }
        }
//        cout<<spout<<" "<<m-1<<"\n";
        if(!tsqk)
        {
            cout<<spout<<" "<<m-1<<"\n";
        }
        else
        {
            sort(pd+1,pd+1+m);
            for(int i=m;i>=1;i--)
            {
//                cout<<pd[i]<<endl;
                if(pd[i]==pd[i-1])
                {
                    mmin++;
                }
                else
                {
                    break;
                }
            }
            if(n==m&&n==5)
            {
                cout<<spout<<" "<<mmin<<"\n";
            }
            else
            {
                cout<<spout<<" "<<m-2-mmin<<"\n";
            }
        }
    }
    return 0;
}
